<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="content"></block>
		</cu-custom>
		<view class="big_tital">欢迎使用 实训管家</view>
		<view class="min_tital">授权微信头像、昵称</view>
		<view>
			<image class="imgBox" :src="img" mode="widthFix"></image>
		</view>
		<view class="login_bottom">
			<button class="bth_login" @tap="login()">
				<text class="iconfont icon-weixin weixin"></text>
				<text class="login_text">微信授权登录</text>
			</button>
		</view>
		<view class="bottom">
				<text>登录代表您已同意</text>
				<text class="text_buttom">《用户服务协议》</text>
				<text class="text_buttom">《隐私权政策》</text>
		</view>
	</view>
	
</template>

<script>
	const {httpGet,httpPost,ZC} = require("@/utils/common.js")
	const app = getApp();
	export default {
		data() {
			return {
				code:'',
				token:'',
				img:'https://zhaojjw.cn/newjbh/20219223611214'
			}
		},
		onLoad(){
			this.getCode()
		},
		methods: {
			getCode(){
				uni.login({
					success:(res)=>{
						this.code = res.code
						// this.token = res.result.token
					}
				})
			},

			login(){
				console.log('点击了按钮')
				var postdata = {};
				uni.getUserProfile({
					desc:'先授权登录',
					success:(res)=>{
						console.log(res)
						postdata.encryptedData = res.encryptedData
						postdata.iv = res.iv
						postdata.code = this.code
						httpPost({
							url:'/api/wx_app_login',
							data:postdata
						}).then((res)=>{
							var token = res.result.token
							console.log(token)
							ZC('user_token',token,-1)
							ZC('user_info',res.result,-1)
							app.globalData.user_info = res.result
							app.globalData.user_token = res.result.token
							app.ws();
							
							var login_back_url = uni.getStorageSync('login_back_url')
							if(!login_back_url)login_back_url = '../index/index';
							console.log(login_back_url)
							uni.reLaunch({
								url:login_back_url
							})
						})
					}
				})
			}
		}
	}
</script>

<style>
page{
	background-color: #FFFFFF;
}
.big_tital{
	font-size: 50rpx;
	margin-top: 140rpx;
	margin-left: 40rpx;
	color: rgb(16,16,16);
}
.min_tital{
	margin-left: 40rpx;
	font-size: 30rpx;
	color: rgb(144,144,144);
	margin-top: 20rpx;
}
.buttom_text{
	font-size: 52rpx;
	color: rgb(80,124,209);
	text-align: center;
	margin-top: 20rpx;
}
.imgBox{
	margin: auto;
	margin-left: 265rpx;
	margin-top: 107rpx;
	width: 245rpx;
}
.login_bottom{
	margin-top: 175rpx;
}
.bth_login{
	width: 640rpx;
	height: 100rpx;
	background-color: #00a0ff;
	border-radius: 10rpx;
	text-align: center;
}
.weixin{
	color: #FFFFFF;
	font-size: 45rpx;
	line-height: 100rpx;
}
.login_text{
	font-size: 34rpx;
	font-weight: 600rpx;
	margin-left: 15rpx;
	color: #FFFFFF;
	line-height: 100rpx;
	font-weight: 520;
}
.bottom{
	width: 100%;
	margin: auto;
	position: absolute;
	bottom: 160rpx;
	text-align: center;
	/* margin-left: 104rpx; */
}
.text_buttom{
	text-align: center;
	color: rgb(82,185,232);
}
</style>
